# Description: Qt ücretsiz sürümü, sürüm 5.x
# URL: http://qt-project.org/
# Packager: alihan-ozturk28@hotmail.com
# Depends on:xorg-proto xorg-libxkbfile xorg-xtrans xorg-libx11 xorg-libxext xorg-libfs xorg-libice xorg-libsm xorg-libxscrnsaver xorg-libxt xorg-libxmu xorg-libxpm xorg-libxaw xorg-libxfixes xorg-libxcomposite xorg-libxrender xorg-libxcursor xorg-libxdamage xorg-libfontenc xorg-libxfont xorg-libxft xorg-libxi xorg-libxinerama xorg-libxrandr xorg-libxres xorg-libxtst xorg-libxv xorg-libxvmc xorg-libxxf86dga xorg-libxxf86vm xorg-libdmx xorg-libpciaccess xorg-libxkbfile xorg-libxshmfence  xcb-proto xcb-util-image xcb-util-keysyms xcb-util-renderutil xcb-util-wm alsa-lib ca-certificates cups dbus glib gstreamer-plugins-base icu jasper libproxy libinput libjpeg-turbo libmng libpng libtiff libwebp xorg-mesa mtdev openssl pcre sqlite ruby gstreamer1-plugins-base geoclue gtk2 harfbuzz postgresql pulseaudio unixodbc libxkbcommon mariadb

name=qt5
version=5.7.0
release=1

_name=qt-everywhere-opensource-src-${version}

source=(http://download.qt.io/official_releases/qt/${version%.*}/$version/single/qt-everywhere-opensource-src-$version.tar.xz
	    assistant.desktop
	    designer.desktop
	    qdbusviewer.desktop
	    linguist.desktop)

build() {

QT5PREFIX=/usr
QT5DIR=$QT5PREFIX/lib/qt5
QT5BINDIR=$QT5PREFIX/lib/qt5/bin

cd ${_name}*

./configure  -prefix $QT5PREFIX                          \
             -bindir $QT5BINDIR                          \
             -headerdir /usr/include/qt5                 \
             -archdatadir $QT5DIR                        \
             -libdir /usr/lib                            \
             -docdir /usr/share/doc/qt5                  \
             -plugindir /usr/lib/qt5/plugins             \
             -importdir /usr/lib/qt5/imports             \
             -qmldir /usr/lib/qt5/qml                    \
             -datadir /usr/share/qt5                     \
             -translationdir /usr/share/qt5/translations \
             -sysconfdir /etc/xdg                        \
             -plugin-sql-{psql,mysql,sqlite,odbc}        \
             -confirm-license  \
             -opensource       \
             -dbus-linked      \
             -openssl-linked   \
             -system-harfbuzz  \
             -system-sqlite    \
	         -optimized-qmake  \
             -nomake examples  \
	         -no-rpath

make
make INSTALL_ROOT=$PKG install

# Fix paths
find $PKG/usr/lib  -type f -name '*.prl' \
	-exec sed -i -e '/^QmAKE_PRL_BUiLD_DiR/d' {} \;
		
sed -e "s|$PWD/qtbase|/usr/lib|g" \
	-i $PKG/usr/lib/qt5/mkspecs/modules/qt_lib_bootstrap_private.pri

install -d $PKG/usr/share/applications
install -m644 $SRC/assistant.desktop $PKG/usr/share/applications/
install -m644 $SRC/designer.desktop $PKG/usr/share/applications/
install -m644 $SRC/linguist.desktop $PKG/usr/share/applications/
install -m644 $SRC/qdbusviewer.desktop $PKG/usr/share/applications/

mkdir -p $PKG/etc/profile.d
cat > $PKG/etc/profile.d/qt5.sh << EOf
# Begin /etc/profile.d/qt5.sh

QT5PREFIX=$QT5PREFIX
QT5DIR=$QT5PREFIX/lib/qt5
QT5BINDIR=$QT5PREFIX/lib/qt5/bin
export QT5PREFIX QT5BINDIR QT5DIR

# End /etc/profile.d/qt5.sh
EOf

### symlink /usr/lib/qt5/bin
mkdir -p $PKG/usr/bin

for i in $PKG/usr/lib/qt5/bin/*; do 
	ln -sv /usr/lib/qt5/bin/$(basename $i) $PKG/usr/bin/$(basename $i)-qt5
done

cat > $PKG/usr/bin/setqt5 << EOF
if [ "x\$QT4BINDIR" != "x/usr/bin" ] && [ "x\$QT4BINDIR" != "x" ]; then pathremove $QT4BINDIR; fi
if [ "x\$QT5BINDIR" != "x/usr/bin" ]; then pathprepend $QT5BINDIR; fi
echo \$PATH
EOF

rm -rf $PKG/usr/share/doc

}
